package pers.linkong.asr.service;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Isolation;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import pers.linkong.asr.domain.TeacherBean;
import pers.linkong.asr.mapper.TeacherMapper;

@Service
// Service组件
@Transactional(propagation = Propagation.REQUIRED, isolation = Isolation.SERIALIZABLE, readOnly = false)
public class TeacherService {
	@Autowired
	private TeacherMapper teacherMapper;

	// 增
	public void addTeacher(TeacherBean teacher) throws Exception {
		this.teacherMapper.addTeacher(teacher);
		System.out.println("添加教师：" + teacher.getTid());
		// throw new RuntimeException();
	}

	// 删
	public void deleteTeacher(int Tid) throws Exception {
		this.teacherMapper.deleteTeacher(Tid);
		System.out.println("删除教师：" + Tid);
	}

	// 查
	public TeacherBean getTeacherById(int id) throws Exception {
		TeacherBean teacher = teacherMapper.getTeacherById(id);
		System.out.println("查询教师：" + teacher.getTname());
		return teacher;
	}

	// 改
	public void updateTeacher(TeacherBean teacher) throws Exception {
		this.teacherMapper.updateTeacher(teacher);
		System.out.println("修改教师：" + teacher.getTname());
	}

	// 分页
	public List<TeacherBean> findTeacherByPage(TeacherBean teacher, long start,
			long limit) throws Exception {
		List<TeacherBean> teacherBeans = this.teacherMapper.findTeacherByPage(teacher, start, limit);
		return teacherBeans;
	}
	
	// 统计
	public long getTeacherCount(TeacherBean teacher) throws Exception {
		return this.teacherMapper.getTeacherCount(teacher);
	}
	
	// 登录
	public TeacherBean login(int tid, String tpass){
		return this.teacherMapper.login(tid, tpass);
	}
}
